package com.ruoyi.monitor.infoprojectmonitorrelation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.monitor.infoprojectmonitorfunds.domain.InfoProjectMonitorFunds;
import com.ruoyi.monitor.infoprojectmonitorrelation.vo.InfoProjectMonitorDetailVo;
import com.ruoyi.monitor.infoprojectmonitorrelation.vo.InfoProjectMonitorExamineVo;
import com.ruoyi.monitor.infoprojectmonitorrelation.domain.InfoProjectMonitorRelation;
import com.ruoyi.monitor.infoprojectmonitorrelation.service.IInfoProjectMonitorRelationService;
import com.ruoyi.monitor.infoprojectmonitorrelation.vo.InfoProjectMonitorReportVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目监控 关联资金和指标 中间Controller
 *
 * @author ruoyi
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/infoProjectMonitorRelation/infoProjectMonitorRelation")
public class InfoProjectMonitorRelationController extends BaseController {
    @Autowired
    private IInfoProjectMonitorRelationService infoProjectMonitorRelationService;

    /**
     * 预算单位项目监控 可以上报的项目列表查询
     *
     * @param monitorReportVo
     * @return
     */
    @RequestMapping(value = "/reportProjectMonitorList", method = RequestMethod.GET)
    public TableDataInfo reportProjectMonitorList(InfoProjectMonitorReportVo monitorReportVo) {
        //只查询当前登录的预算单位自己的填报项数据
        monitorReportVo.setReleaseDepartmentId(SecurityUtils.getDeptId());
        startPage();
        List<InfoProjectMonitorReportVo> list = infoProjectMonitorRelationService.reportProjectMonitorList(monitorReportVo);
        return getDataTable(list);
    }

    /**
     * 查询项目监控 关联资金和指标 中间列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoProjectMonitorRelation infoProjectMonitorRelation) {
        startPage();
        List<InfoProjectMonitorRelation> list = infoProjectMonitorRelationService.selectInfoProjectMonitorRelationList(infoProjectMonitorRelation);
        return getDataTable(list);
    }

    /**
     * 导出项目监控 关联资金和指标 中间列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:export')")
    @Log(title = "项目监控 关联资金和指标 中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoProjectMonitorRelation infoProjectMonitorRelation) {
        List<InfoProjectMonitorRelation> list = infoProjectMonitorRelationService.selectInfoProjectMonitorRelationList(infoProjectMonitorRelation);
        ExcelUtil<InfoProjectMonitorRelation> util = new ExcelUtil<InfoProjectMonitorRelation>(InfoProjectMonitorRelation.class);
        util.exportExcel(response, list, "项目监控 关联资金和指标 中间数据");
    }

    /**
     * 获取项目监控 关联资金和指标 中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoProjectMonitorRelationService.selectInfoProjectMonitorRelationById(id));
    }

    /**
     * 新增项目监控 关联资金和指标 中间
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:add')")
    @Log(title = "项目监控 关联资金和指标 中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoProjectMonitorRelation infoProjectMonitorRelation) {
        return toAjax(infoProjectMonitorRelationService.insertInfoProjectMonitorRelation(infoProjectMonitorRelation));
    }

    /**
     * 修改项目监控 关联资金和指标 中间
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:edit')")
    @Log(title = "项目监控 关联资金和指标 中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoProjectMonitorRelation infoProjectMonitorRelation) {
        return toAjax(infoProjectMonitorRelationService.updateInfoProjectMonitorRelation(infoProjectMonitorRelation));
    }

    /**
     * 删除项目监控 关联资金和指标 中间
     */
    @PreAuthorize("@ss.hasPermi('infoProjectMonitorRelation:infoProjectMonitorRelation:remove')")
    @Log(title = "项目监控 关联资金和指标 中间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoProjectMonitorRelationService.deleteInfoProjectMonitorRelationByIds(ids));
    }

    /**
     * 删除项目监控 关系表
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteProjectMonitorRelation/{id}", method = RequestMethod.DELETE)
    public AjaxResult deleteProjectMonitorRelation(@PathVariable Long id) {
        return toAjax(infoProjectMonitorRelationService.deleteProjectMonitorRelation(id));
    }

    /**
     * 审核监控
     *  单条监控状态 0 未下达 1 待填报 2 等待主管处室审核 3 审计处审核中（主管处室通过) 4 驳回 5通过（审计处）
     * @param infoProjectMonitorExamineVo
     * @return
     */
    @RequestMapping(value = "/examineProjectMonitor", method = RequestMethod.POST)
    public AjaxResult examineProjectMonitor(@RequestBody InfoProjectMonitorExamineVo infoProjectMonitorExamineVo) {
        return toAjax(infoProjectMonitorRelationService.examineProjectMonitor(infoProjectMonitorExamineVo));
    }

    /**
     * 预算单位填报资金使用情况
     * 只修改资金的使用情况 指标直接在表格操作栏调取接口修改
     *
     * @param infoProjectMonitorFunds
     * @return
     */
    @RequestMapping("/saveProjectMonitorItem")
    public AjaxResult saveProjectMonitorItem(@RequestBody InfoProjectMonitorFunds infoProjectMonitorFunds) {
        return toAjax(infoProjectMonitorRelationService.saveProjectMonitorItem(infoProjectMonitorFunds));
    }


    /**
     * 根据项目监控关系表查询详情
     *
     * @param relationMonitorId
     * @return
     */
    @RequestMapping(value = "/getProjectMonitorDetail", method = RequestMethod.GET)
    public AjaxResult getProjectMonitorDetail(@RequestParam("relationMonitorId") Long relationMonitorId) {
        InfoProjectMonitorDetailVo detailVo = infoProjectMonitorRelationService.getProjectMonitorDetail(relationMonitorId);
        return AjaxResult.success(detailVo);
    }

}
